<?php
require 'vendor/autoload.php';

class PreferencesManager{

	private $feedsXml;
	private $sourceArray;
	private $cookieManager;

	function __construct($cookieManager){
		$this->cookieManager = $cookieManager;
	}

	function setFeedsXml($feedsXml){
		$this->feedsXml = $feedsXml;
	}

	function setSourceArray($feedsXml){
		$this->sourceArray = simplexml_load_file($feedsXml);
	}

	function getSourceArray(){
		return $this->sourceArray;
	}

	function runConfiguration(){
		$this->setSourceArray($this->feedsXml);
		$this->cookieManager->setupCookie();
	}

	function isSourceEnabled($source){
		$shortName = (string) $source->shortName;
		$cookie = $this->cookieManager->getCookie();

		for($i=0; $i<sizeof($this->sourceArray); $i++){
			if ($cookie[$i]['shortname']==$shortName){
				return $cookie[$i]['value'];
			}
		}
		// If not found
		return false;
	}

}

?>